﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BLL;
using System.Collections;
using System.Configuration;
using Newtonsoft.Json;

namespace Sales
{
    public partial class MemberList : Form
    {
        public SysConfig config;
     
        public Common2 common = new Common2();

        public HykblHBLL hykblhBLL;// = new HykblHBLL();
        public MemberList()
        {
            config = Common2.GetConfig();//获取相关配置属性 
            hykblhBLL = new HykblHBLL(config.WebApi);
            InitializeComponent();
            SetdataGridStyle();
            curPage = 1;
        }
        private static MemberList memberList = null;


        public static MemberList CreateInstance()
        {
            if (null == memberList)
            {
                memberList = new MemberList();
            }
            return memberList;
        }


        #region 页面属性

        public const int pageSize = 10;

        public int curPage//当前页
        {
            get;
            set;
        }
        public int TotalPage//总页数 
        {
            get;
            set;
        }

        /// <summary>
        /// 店面编号 
        /// </summary>
        public string Dmbh
        {
            set;
            get;
        }
        /// <summary>
        /// 店面名称
        /// </summary>
        public string Dmmc
        {
            set;
            get;
        }

        /// <summary>
        /// 营业员
        /// </summary>
        public string Yyy
        {
            set;
            get;
        }
        /// <summary>
        /// 查询条件
        /// </summary>
        public int QueryStatus
        {
            set;
            get;
        }

        #endregion

        /// <summary>
        /// 样式
        /// </summary>
        /// <param name="dt"></param>
        private void SetdataGridStyle()
        {
            try
            {
                this.dataGridView1.RowHeadersVisible = true;

                //卡号    
                DataGridViewTextBoxColumn dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "卡号";
                dc.DataPropertyName = "kh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[0].Width = 110;
                this.dataGridView1.Columns[0].ReadOnly = true;

                //客户名称    
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "客户名称";
                dc.DataPropertyName = "khmc";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[1].Width = 110;
                this.dataGridView1.Columns[1].ReadOnly = true;


                // 
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "店面编号";
                dc.DataPropertyName = "dmbh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[2].Width = 90;
                this.dataGridView1.Columns[2].ReadOnly = true;
                //  this.dataGridView1.Columns[0].Visible = false;
                //this.dataGridView1.Visible = false;

                //店面名称
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "店面名称";
                dc.DataPropertyName = "dmmc";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[3].Width = 110;
                this.dataGridView1.Columns[3].ReadOnly = true;





                //折扣 ,,, ,
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "折扣";
                dc.DataPropertyName = "hyzk";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[4].Width = 110;
                this.dataGridView1.Columns[4].ReadOnly = true;
                this.dataGridView1.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

                //余额
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "余额";
                dc.DataPropertyName = "hykye";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[5].Width = 110;
                this.dataGridView1.Columns[5].ReadOnly = true;
                //  this.dataGridView1.Columns[5].Visible = false;

                //最近消费金额
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "最近消费金额";
                dc.DataPropertyName = "zjxfjf";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[6].Width = 130;
                // this.dataGridView1.Columns[6].Visible = false;

                //最近消费时间 ,
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "最近消费时间";
                dc.DataPropertyName = "zjxfsj";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[7].Width = 130;
                this.dataGridView1.Columns[7].ReadOnly = true;
                // this.dataGridView1.Columns[7].Visible = false;

                //会员卡状态  
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "会员卡状态";
                dc.DataPropertyName = "hykzt";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[8].Width = 90;
                // this.dataGridView1.Columns[8].Visible = false;

                //登记用户 
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "登记用户";
                dc.DataPropertyName = "djyh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[9].Width = 90;
                this.dataGridView1.Columns[9].ReadOnly = true;
                //  this.dataGridView1.Columns[9].Visible = false;


                //登记时间
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "登记时间";
                dc.DataPropertyName = "djsj";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[10].Width = 110;


                //修改用户
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "修改用户";
                dc.DataPropertyName = "xgyh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[11].Width = 100;
                this.dataGridView1.Columns[11].ReadOnly = true;


                //修改时间
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "修改时间";
                dc.DataPropertyName = "xgsj";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[12].Width = 100;


                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "单据流水号";
                dc.DataPropertyName = "DjLsh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[13].Width = 100;
                this.dataGridView1.Columns[13].Visible = false;


                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "单据表体流水号";
                dc.DataPropertyName = "DjBtZdh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[14].Width = 100;
                this.dataGridView1.Columns[14].Visible = false;
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "单据附体流水号";
                dc.DataPropertyName = "DjFtZdh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[15].Width = 100;
                this.dataGridView1.Columns[15].Visible = false;
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "单据孙体流水号";
                dc.DataPropertyName = "DjStZdh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[16].Width = 100;
                this.dataGridView1.Columns[16].Visible = false;


                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "单据状态";
                dc.DataPropertyName = "DjState";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[17].Width = 100;
                this.dataGridView1.Columns[17].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "值";
                dc.DataPropertyName = "DjCount";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[18].Width = 100;
                this.dataGridView1.Columns[18].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "客户编号";
                dc.DataPropertyName = "khbh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[19].Width = 100;
                this.dataGridView1.Columns[19].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "电话";
                dc.DataPropertyName = "dh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[20].Width = 100;
                this.dataGridView1.Columns[20].Visible = false;



                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "地址";
                dc.DataPropertyName = "dz";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[21].Width = 100;
                this.dataGridView1.Columns[21].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "单据流水号";
                dc.DataPropertyName = "xfzjf";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[22].Width = 100;
                this.dataGridView1.Columns[22].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "积分余额";
                dc.DataPropertyName = "jfye";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[23].Width = 100;
                //   this.dataGridView1.Columns[23].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "日期";
                dc.DataPropertyName = "rq";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[24].Width = 100;
                this.dataGridView1.Columns[24].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "时间";
                dc.DataPropertyName = "sj";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[25].Width = 100;
                this.dataGridView1.Columns[25].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "密码";
                dc.DataPropertyName = "mm";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[26].Width = 100;
                this.dataGridView1.Columns[26].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "备注";
                dc.DataPropertyName = "bz";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[27].Width = 100;
                this.dataGridView1.Columns[27].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "srmm";
                dc.DataPropertyName = "srmm";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[28].Width = 100;
                this.dataGridView1.Columns[28].Visible = false;

                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "cfsrmm";
                dc.DataPropertyName = "cfsrmm";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[29].Width = 100;
                this.dataGridView1.Columns[29].Visible = false;
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "sfz";
                dc.DataPropertyName = "sfz";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[30].Width = 100;
                this.dataGridView1.Columns[30].Visible = false;
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "sr";
                dc.DataPropertyName = "sr";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[31].Width = 100;
                this.dataGridView1.Columns[31].Visible = false;


                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "xb";
                dc.DataPropertyName = "xb";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[32].Width = 100;
                this.dataGridView1.Columns[32].Visible = false;
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "ykh";
                dc.DataPropertyName = "ykh";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[33].Width = 100;
                this.dataGridView1.Columns[33].Visible = false;
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "IndexCount";
                dc.DataPropertyName = "IndexCount";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[34].Width = 100;
                this.dataGridView1.Columns[34].Visible = false;
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "sffsdx";
                dc.DataPropertyName = "sffsdx";
                dc.HeaderCell.Style.Font = new Font("宋体", 10, FontStyle.Bold);
                dc.HeaderCell.Style.ForeColor = Color.Blue;
                dc.DefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Bold);
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[35].Width = 100;
                this.dataGridView1.Columns[35].Visible = false;

            }
            catch { }
        }
        private void stbtnAdd_Click(object sender, EventArgs e)
        {
            MemberManagement memberManagement = MemberManagement.CreateInstance();
            //店面编号、店面名称、营业员

            MemberInfo m1 = new MemberInfo();
            m1.Hykh = "";
            m1.Dmbh = Dmbh;
            m1.Dmmc = Dmmc;
            m1.Yyymc = Yyy;

            string msg = JsonConvert.SerializeObject(m1);
            MiddleModule.SendMessage(this, memberManagement, msg);
            if (!memberManagement.Visible)
                memberManagement.ShowDialog();
        }

        private void tsbtnUpdate_Click(object sender, EventArgs e)
        {
            MemberManagement memberManagement = MemberManagement.CreateInstance();

            //会员卡号、店面编号、店面名称、营业员
            //   string msg = "";// Hykh + "," + Dmbh + "," + Dmmc + "," + Yyymc;

            MemberInfo m1 = new MemberInfo();
            m1.Hykh = "";
            m1.Dmbh = Dmbh;
            m1.Dmmc = Dmmc;
            m1.Yyymc = Yyy;
            string msg = JsonConvert.SerializeObject(m1);
            MiddleModule.SendMessage(this, memberManagement, msg);

            if (!memberManagement.Visible)
                memberManagement.ShowDialog();
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            string ss = this.txtPage.Text;
            if (ss != "")
            {
                if (int.Parse(ss) > TotalPage || int.Parse(ss) < 1)
                {
                    Message.Warning("输入页号不合格请重新输入！");
                }

                curPage = int.Parse(ss);

                if (curPage == TotalPage)
                {
                    lblCurPage.Text = "第" + curPage + "页";


                    btnFirst.Enabled = true;
                    btnBack.Enabled = true;
                    btnNext.Enabled = false;
                    btnLast.Enabled = false;
                }
                else if (curPage == 1)
                {
                    lblCurPage.Text = "第" + curPage + "页";

                    btnFirst.Enabled = false;
                    btnBack.Enabled = false;
                    btnNext.Enabled = true;
                    btnLast.Enabled = true;

                }
                else
                {
                    lblCurPage.Text = "第" + curPage + "页";
                    btnFirst.Enabled = true;
                    btnBack.Enabled = true;
                    btnNext.Enabled = true;
                    btnLast.Enabled = true;
                }




                //绑定数据
                NewDataBind(curPage, 1);

            }
            else
            {
                Message.Warning("请输入页号！");
            }
        }

        private void btnFirst_Click(object sender, EventArgs e)
        {
            curPage = 1;
            lblCurPage.Text = "第" + curPage + "页";


            btnFirst.Enabled = false;
            btnBack.Enabled = false;
            btnNext.Enabled = true;
            btnLast.Enabled = true;


            NewDataBind(1, 1);

        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            if (curPage > 1)
            {
                curPage--;
                lblCurPage.Text = "第" + curPage + "页";


                //绑定数据
                NewDataBind(curPage, 1);


                if (curPage != 1)
                {
                    btnFirst.Enabled = true;
                    btnBack.Enabled = true;
                    btnNext.Enabled = true;
                    btnLast.Enabled = true;
                }
                else
                {
                    btnFirst.Enabled = false;
                    btnBack.Enabled = false;
                    btnNext.Enabled = true;
                    btnLast.Enabled = true;
                }
            }

        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (curPage < TotalPage)
            {
                curPage++;
                lblCurPage.Text = "第" + curPage + "页";

                //绑定数据
                NewDataBind(curPage, 1);

                if (curPage != TotalPage)
                {
                    btnFirst.Enabled = true;
                    btnBack.Enabled = true;
                    btnNext.Enabled = true;
                    btnLast.Enabled = true;
                }
                else
                {
                    btnFirst.Enabled = true;
                    btnBack.Enabled = true;
                    btnNext.Enabled = false;
                    btnLast.Enabled = false;
                }

            }
        }

        private void btnLast_Click(object sender, EventArgs e)
        {
            curPage = TotalPage;
            lblCurPage.Text = "第" + curPage + "页";

            //绑定数据
            NewDataBind(curPage, 1);


            btnFirst.Enabled = true;
            btnBack.Enabled = true;
            btnNext.Enabled = false;
            btnLast.Enabled = false;
        }

        private void NewDataBind(int curPage, int type)
        {
            int thcurPage = 1;
            if (type == 1)
                thcurPage = curPage;

            if (QueryStatus == 1)
            {
                string value = this.ctxtKey.Text.Trim();
                string time1 = this.dateTimePicker1.Value.ToString("yyyy-MM-dd") + " 00:00:00";
                string time2 = this.dateTimePicker2.Value.ToString("yyyy-MM-dd") + " 23:59:59";
                //select * from hykblH  where dmbh='8079'  and (kh like '%%' or khmc like '%%')
                InitPage(value, time1, time2);
                BindShdData(value, time1, time2, thcurPage);
            }
            else
            {
                BindShdData(thcurPage);
            }
        }
        private void BindShdData(int start)
        {
            List<hykblH_Entity> ls = hykblhBLL.GetHykblHList(Dmbh, start, pageSize);
            this.dataGridView1.DataSource = ls;
        }
        private void BindShdData(string value, string time1, string time2, int start)
        {
            List<hykblH_Entity> ls = hykblhBLL.GetHykblHList(Dmbh, value, time1, time2, start, pageSize);
            this.dataGridView1.DataSource = ls;
        }

        private void InitPage()
        {

            int count = hykblhBLL.HykblCount0(Dmbh);

            if (count > 0)
            {
                if (count > pageSize)
                {
                    btnFirst.Enabled = false;
                    btnBack.Enabled = false;
                    btnNext.Enabled = true;
                    btnLast.Enabled = true;
                    int length = count / pageSize;
                    if (count % pageSize > 0)
                    {
                        length++;
                    }
                    lblTotalpage.Text = "共" + length + "页";
                    TotalPage = length;
                    lblCurPage.Text = "第1页";
                }
                else
                {
                    btnFirst.Enabled = false;
                    btnBack.Enabled = false;
                    btnNext.Enabled = false;
                    btnLast.Enabled = false;

                    lblTotalpage.Text = "共1页"; TotalPage = 1;
                    lblCurPage.Text = "第1页";
                }

            }
            else
            {
                btnFirst.Enabled = false;
                btnBack.Enabled = false;
                btnNext.Enabled = false;
                btnLast.Enabled = false;
                TotalPage = 0;
                curPage = 0;
                //          
            }
        }

        private void InitPage(string value, string time1, string time2)
        {

            int count = hykblhBLL.HykblCount1(Dmbh, value, time1, time2);

            if (count > 0)
            {
                if (count > pageSize)
                {
                    btnFirst.Enabled = false;
                    btnBack.Enabled = false;
                    btnNext.Enabled = true;
                    btnLast.Enabled = true;
                    int length = count / pageSize;
                    if (count % pageSize > 0)
                    {
                        length++;
                    }
                    lblTotalpage.Text = "共" + length + "页";
                    TotalPage = length;
                    lblCurPage.Text = "第1页";
                }
                else
                {
                    btnFirst.Enabled = false;
                    btnBack.Enabled = false;
                    btnNext.Enabled = false;
                    btnLast.Enabled = false;

                    lblTotalpage.Text = "共1页"; TotalPage = 1;
                    lblCurPage.Text = "第1页";
                }

            }
            else
            {
                btnFirst.Enabled = false;
                btnBack.Enabled = false;
                btnNext.Enabled = false;
                btnLast.Enabled = false;
                TotalPage = 0;
                curPage = 0;
                //          
            }
        }



        private void MemberList_Load(object sender, EventArgs e)
        {
            InitPage();

            BindShdData(1);



        }

        private void MemberList_FormClosed(object sender, FormClosedEventArgs e)
        {
            memberList = null;
        }

        private void stbtnAdd_Click_1(object sender, EventArgs e)
        {
            MemberManagement memberManagement = MemberManagement.CreateInstance();
            //会员卡号、店面编号、店面名称、营业员
            //  string msg = "" + "," + Dmbh + "," + Dmmc + "," + Yyy;

            MemberInfo model = new MemberInfo();
            model.Dmbh = Dmbh;
            model.Dmmc = Dmmc;
            model.Hykh = "";
            model.Yyymc = Yyy;
            string msg = JsonConvert.SerializeObject(model);

            MiddleModule.SendMessage(this, memberManagement, msg);

            if (!memberManagement.Visible)
            {
                memberManagement.ShowDialog();
                NewDataBind(1, 1);
            }
        }

        private void tsbtnUpdate_Click_1(object sender, EventArgs e)
        {
            MemberManagement memberManagement = MemberManagement.CreateInstance();
            int index = this.dataGridView1.SelectedCells[0].RowIndex;
            hykblH_Entity entity = (hykblH_Entity)this.dataGridView1.Rows[index].DataBoundItem;
            if (entity != null)
            {

                string kh = entity.kh;
                MemberInfo model = new MemberInfo();
                model.Dmbh = Dmbh;
                model.Dmmc = Dmmc;
                model.Hykh = kh;
                model.Yyymc = Yyy;
                string msg = JsonConvert.SerializeObject(model);
                MiddleModule.SendMessage(this, memberManagement, msg);

                if (!memberManagement.Visible)
                {
                    memberManagement.ShowDialog();
                    NewDataBind(curPage, 1);
                }
            }
        }

        private void tsbtnDelete_Click(object sender, EventArgs e)
        {
            int index = this.dataGridView1.SelectedCells[0].RowIndex;
            hykblH_Entity entity = (hykblH_Entity)this.dataGridView1.Rows[index].DataBoundItem;
            if (entity != null)
            {
                string kh = entity.kh;
                int ss = hykblhBLL.DeleteHykblByWebApi(kh);
                if (ss > 0)
                {
                    MessageBox.Show("删除成功");
                    NewDataBind(curPage, 1);
                }
                else
                    MessageBox.Show("删除失败");
            }


        
        }

        private void gbtnQuery_Click(object sender, EventArgs e)
        {
            QueryStatus = 1;
            curPage = 1;

            lblCurPage.Text = "第" + curPage + "页";


            btnFirst.Enabled = false;
            btnBack.Enabled = false;
            btnNext.Enabled = true;
            btnLast.Enabled = true;


            NewDataBind(1, 0);
        }

        private void gbtnClear_Click(object sender, EventArgs e)
        {
            QueryStatus = 0;
            this.ctxtKey.Text = "";
        }
    }
}
